package qlvbdq.bo;

import java.sql.SQLException;
import qlvbdq.dao.UserDAO;
import qlvbdq.dto.UserDTO;

/**
 *
 * @author THAI HA
 */
public class UserBO {

    public UserBO() {
    }

    /**
     * @description kiem tra dang nhap
     * @param userDTO_ thong tin dang nhap
     * @return true neu dung tai khoan va mat khau
     */
    public boolean logIn(UserDTO userDTO_) {
        boolean result = false;
        UserDAO userDAO = new UserDAO();
        try {
            UserDTO userData
                    = userDAO.getUserByUserNameFromDatabase(userDTO_.getUserName());
            String oldPass = userData.getPassword();
            oldPass = oldPass.replaceAll(" ", "");
            String inPutPass = userDTO_.getPassword();
            if (oldPass.equals(inPutPass)) {
                result = true;
            }
        } catch (SQLException ex) {
            System.out.println("Không thể kết nối CSDL");
        }
        return result;
    }

    /**
     * @description thay doi mat khau nguoi dung
     * @param userDTO_
     * @return
     */
    public boolean changeInfoUser(UserDTO userDTO_, String newPassword) {
        boolean result = false;
        UserDAO userDAO = new UserDAO();
        if (userDAO.updateUserToDatabase(userDTO_) > 0) {
            result = true;
        }
        return result;
    }

    public boolean addUser(UserDTO userDTO_) {
        boolean result = false;
        UserDAO userDAO = new UserDAO();
        if (userDAO.InsertUserToDatabase(userDTO_) > 0) {
            result = true;
        }
        return result;
    }
}
